package com.shujia

class A(id: String, name: String) {
  val _id: String = id
  val _name: String = name


  override def toString = s"A(_id=${_id}, _name=${_name})"

  def printAB(): Unit = {
    println("这是A的对象方法")
  }
}


class B(id: String, name: String, age: Int, clazz: String) extends A(id, name) {
  val _age: Int = age
  val _clazz: String = clazz


  override def toString = s"B(_id=${_id},_name=${_name},_age=${_age}, _clazz=${_clazz})"

  override def printAB(): Unit = {
    println("这是B的对象方法")
  }
}

object Demo4obj {


  def printTwice(a: A): Unit = {
    a.printAB()
    a.printAB()
  }


  def main(args: Array[String]): Unit = {
    val a: A = new A("001", "张三")
    val b: B = new B("002", "李四", 21, "文科一班")

    println(a._id)
    println(a._name)
    println(a)

    println(b._id)
    println(b._name)
    println(b._age)
    println(b._clazz)
    println(b)

    a.printAB()
    b.printAB()

    printTwice(b) // 多态 父类引用指向子类对象

    printTwice(a)

    // 样例类
    val caseStu: Demo5CaseClass = new Demo5CaseClass("003", "小明", 22, "男", "理科三班")

  }
}
